home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Include / FWOnStac.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  5.5 KB  |  183 lines  |  [TEXT/MPS ]

  1. #ifndef FWONSTAC_H
  2. #define FWONSTAC_H
  3.  
  4. //========================================================================================
  5. //
  6. //    File:                FWOnStac.h
  7. //    Release Version:    $ 1.0d11 $
  8. //
  9. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef FW_NATIVE_EXCEPTIONS
  14.  
  15. #if !defined(FWPRIDEB_H) && defined(FW_BUILD_WIN)
  16. #include "FWPriDeb.h"
  17. #endif
  18.  
  19. #if !defined(__CONDITIONALMACROS__) && defined(FW_BUILD_MAC)
  20. #include "ConditionalMacros.h"
  21. #endif
  22.  
  23. #if FW_LIB_EXPORT_PRAGMAS
  24. #pragma lib_export on
  25. #endif
  26.  
  27. extern "C" int FW_FUNC_ATTR _FW_PrivIsOnStack(void *);
  28.  
  29. #ifdef FW_BUILD_MAC
  30.  
  31.  
  32. #if !CFMSYSTEMCALLS && GENERATING68K
  33. #define FW_NINEWORDINLINE(w1, w2, w3, w4, w5, w6, w7, w8, w9)  \
  34.     = {w1,w2,w3,w4,w5,w6,w7,w8,w9}
  35. // Slow version for use if (_FW_PrivIsOnStack()) xxx; works for near and far data
  36. extern "C"
  37. {
  38.     #pragma parameter __D0 _FW_PrivIsOnStack(__A0)
  39.     int _FW_PrivIsOnStack(void *)
  40.         FW_NINEWORDINLINE(0x7000, 0xBFC8, 0x6408, 0xB1F8, 0x0908, 0x6202, 0x7001, 0x4880, 0x48C0);
  41. }
  42. /*
  43. 00000                              OnStackCheck PROC
  44. 00000                                      ;movea.l    a4,a0    ; 4 compiler generated move
  45. 00000   7000                               moveq    #0,d0
  46. 00002   BFC8                               cmpa.l    a0,a7
  47. 00004   6408            0000E              bcc.s    @1
  48. 00006   B1F8 0908                          cmpa.l    $908,a0
  49. 0000A   6202            0000E              bhi.s    @1
  50. 0000C   7001                               moveq    #1,d0
  51. 0000E                                  @1:
  52. 0000E   4880                               ext.w    d0
  53. 00010   48C0                               ext.l    d0
  54. 00012                                  ENDPROC
  55. */
  56. #endif
  57.  
  58. #if 0
  59. // Near data version
  60. extern "C"
  61. {
  62.     #pragma parameter _FW_PrivIsOnStack(__A0)
  63.     void _FW_PrivIsOnStack(void *)
  64.         FIVEWORDINLINE(0xBFC8, 0x6210, 0xB1F8, 0x0908, 0x620A);
  65. }
  66. /*
  67. 00000                              OnStack    PROC
  68. 00000                                      ;movea.l    a4,a0    ; 4 compiler generated move
  69. 00000   BFC8                               cmpa.l    a0,a7        ; 6
  70. 00002   6210            00014              bhi.s    @1            ; 10/8
  71. 00004   B1F8 0908                          cmpa.l    $908,a0        ; 6
  72. 00008   620A            00014              bhi.s    @1            ; 10/8
  73. 0000A   2F0C                               move.l    a4,-(a7)
  74. 0000C   486D 001E                          pea        30(a5)
  75. 00010   4EAD 001E                          jsr        30(a5)        ; 18
  76. 00014                                  @1:
  77. 00014   4E71                               nop
  78. 00016                                  ENDPROC
  79. */
  80. #endif
  81.  
  82. #if 0
  83. // Far data version for when the code is compiled with the -m option.
  84. extern "C"
  85. {
  86.     #pragma parameter _FW_PrivIsOnStack(__A0)
  87.     void _FW_PrivIsOnStack(void *)
  88.         FIVEWORDINLINE(0xBFC8, 0x6218, 0xB1F8, 0x0908, 0x6212);
  89. }
  90. /*
  91. 00000                              OnStackFar    PROC
  92. 00000                                      ;movea.l    a4,a0    ; 4 compiler generated move
  93. 00000   BFC8                               cmpa.l    a0,a7        ; 6
  94. 00002   6218            0001C              bhi.s    @1            ; 10/8
  95. 00004   B1F8 0908                          cmpa.l    $908,a0        ; 6
  96. 00008   6212            0001C              bhi.s    @1            ; 10/8
  97. 0000A   2F0C                               move.l    a4,-(a7)
  98. 0000C   204D                               movea.l    a5,a0
  99. 0000E   D1FC 0001 0000                     adda.l    #-$FFFF0000,a0
  100. 00014   4855                               pea        (a5)
  101. 00016   4EAD 001E                          jsr        30(a5)        ; 18
  102. 0001A   504F                               addq    #8,a7
  103. 0001C                                  @1:
  104. 0001C   4E71                               nop
  105. 0001E                                  ENDPROC
  106. */
  107. #endif
  108.  
  109. #endif
  110.  
  111. #ifdef FW_BUILD_WIN
  112. #ifdef FW_BUILD_WIN16
  113. //----------------------------------------------------------------------------------------
  114. //    WinGetStackBottom
  115. //----------------------------------------------------------------------------------------
  116. inline unsigned short *WinGetStackBottom()
  117. {
  118.     __emit__(0x8C, 0xD2);                // mov DX, SS        2 cycles
  119. #ifndef __BORLANDC__                    
  120.     return (void*)    
  121. #endif
  122.     __emit__(0xB8, 0x0E, 0x00);            // mov AX, 0Eh        2 cycles
  123. #ifdef __BORLANDC__    
  124.     return ((unsigned short *) MAKELP(_DX, _AX));
  125. #endif
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    WinGetStackTop
  130. //----------------------------------------------------------------------------------------
  131. inline unsigned short *WinGetStackTop()
  132. {
  133.     __emit__(0x8C, 0xD2);            // mov DX, SS        2 cycles
  134. #ifndef __BORLANDC__                    
  135.     return (void*)    
  136. #endif    
  137.     __emit__(0xB8, 0x0A, 0x00);        // mov AX, 0Ah        2 cycles
  138. #ifdef __BORLANDC__    
  139.     return ((unsigned short *) MAKELP(_DX, _AX));
  140. #endif
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // _FW_PrivSegmentOf
  145. //----------------------------------------------------------------------------------------
  146. inline unsigned short _FW_PrivSegmentOf(void* p)
  147. {
  148.     return (unsigned short)((unsigned long)p >> 16);
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. // _FW_PrivOffsetOf
  153. //----------------------------------------------------------------------------------------
  154. inline unsigned short _FW_PrivOffsetOf(void* p)
  155. {
  156.     return (unsigned short) p;
  157. }
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // _FW_PrivIsOnStack
  161. //----------------------------------------------------------------------------------------
  162. inline int _FW_PrivIsOnStack(void * p)
  163. {
  164.     int i;
  165.     if (_FW_PrivSegmentOf(p) != _FW_PrivSegmentOf(&i))
  166.         return 0;
  167.     unsigned short top = *WinGetStackTop();
  168.     unsigned short bot = *WinGetStackBottom();
  169.     unsigned short offset = _FW_PrivOffsetOf(p);
  170.     return (offset>top && offset<bot);
  171. }
  172. #endif
  173. #endif
  174.  
  175. #if FW_LIB_EXPORT_PRAGMAS
  176. #pragma lib_export off
  177. #endif
  178.  
  179. #endif // FW_USE_NEW_HELPER
  180.  
  181. #endif
  182.  
  183.